package cn.sz.dzy.cloud.resp;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @program: SpringCloud2024
 * @description:
 * @author: DingZhenYun
 * @create: 2024-04-14 22:38
 **/
@Data
@Accessors(chain = true)
public class ResultData<T> {

    private String code;/** 结果状态 ,具体状态码参见枚举类ReturnCodeEnum.java*/
    private String message;
    private T data;
    private long timestamp;

    public ResultData()
    {
        this.timestamp = System.currentTimeMillis();
    }


    public static <T> ResultData<T> success(T data) {
        return custom(ReturnCodeEnum.RC200.getCode(), ReturnCodeEnum.RC200.getMessage(), data);
    }

    public static <T> ResultData<T> fail(String  code, String massage) {
        return custom(code, massage, null);
    }

    public static <T> ResultData<T> fail() {
        return custom(ReturnCodeEnum.RC999.getCode(), ReturnCodeEnum.RC999.getMessage(), null);
    }

    public static <T> ResultData<T> fail(String massage) {
        return custom("9999", massage, null);
    }

    public static <T> ResultData<T> custom(String code, String massage, T data) {
        ResultData<T> result = new ResultData<T>();
        result.setCode(code);
        result.setMessage(massage);
        result.setData(data);
        return result;
    }
}
